package web;


import pojo.SmbmsProvider;
import service.SmbmsProviderService;
import service.impl.SmbmsProviderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(value = "/providerServlet")
public class ProviderListServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //用户名从页面传值  proName属性获取值
        String proName=req.getParameter("proName");
        if(proName ==null){
            proName="";
        }

        //调用业务层实现
        SmbmsProviderService smbmsProviderService=new SmbmsProviderServiceImpl();


        List<SmbmsProvider> smbmsProviders = null;
        try {
            smbmsProviders = smbmsProviderService.queryList(proName);
            //把数据放在request作用域中
            req.setAttribute("list",smbmsProviders);
            req.setAttribute("proName",proName);
            //转发
            req.getRequestDispatcher("providerList.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
